package com.itheima.app.controller;

import com.itheima.app.mapper.MakeFriendManager;
import com.itheima.vo.NearUserVo;
import com.itheima.vo.PageBeanVo;
import com.itheima.vo.RecommendUserVo;
import com.itheima.vo.VisitorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class MakeFriendController {

    @Autowired
    private MakeFriendManager makeFriendManager;

    //今日佳人
    @GetMapping("/tanhua/todayBest")
    public RecommendUserVo findTodayBest(){
        return makeFriendManager.findTodayBest();
    }

    //推荐用户列表
    @GetMapping("/tanhua/recommendation")
    public PageBeanVo findRecommendUser(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return makeFriendManager.findRecommendUser(pageNum,pageSize);
    }

    //查询佳人信息
    @GetMapping("/tanhua/{id}/personalInfo")
    public RecommendUserVo findPersonalInfo(@PathVariable("id") Long id){
        return makeFriendManager.findPersonalInfo(id);
    }

    //最近访客
    @GetMapping("/movements/visitors")
    public List<VisitorVo> findVisitor(){
        return makeFriendManager.findVisitor();
    }

    //查询陌生人问题
    @GetMapping("/tanhua/strangerQuestions")
    public String findStrangerQuestions(Long userId){
        return makeFriendManager.findStrangerQuestions(userId);
    }

    //回答陌生人问题（打招呼）
    @PostMapping("/tanhua/strangerQuestions")
    public void replyStrangerQuestion(@RequestBody Map<String,String> map){
        //陌生人id
        long strangerId = Long.parseLong(map.get("userId"));
        String reply = map.get("reply");
        System.out.println("reply:"+reply);
        // 2.调用manager
        makeFriendManager.replyStrangerQuestion(strangerId,reply);
    }

    //添加好友
    @PostMapping("/messages/contacts")
    public void addContacts(@RequestBody Map<String,String> map){
        //获取参数
        long friendId = Long.parseLong(map.get("userId"));//好友id
        //调用manager
        makeFriendManager.addContacts(friendId);
    }

    //分页查询我的所有好友
    @GetMapping("//messages/contacts")
    public PageBeanVo findContact( @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                   @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize){
        return makeFriendManager.findContact(pageNum,pageSize);
    }


    //搜索附近的人
    @GetMapping("/tanhua/search")
    public List<NearUserVo> findNearUser(String gender, Long distance) {
        System.out.println(gender);
        return makeFriendManager.findNearUser(gender, distance);
    }


    //探花--卡片展示
    @GetMapping("/tanhua/cards")
    public List<RecommendUserVo> findCards(){
        return (List<RecommendUserVo>) makeFriendManager.findRecommendUser(1,20).getItems();
    }
}